package com.media.themovieworld.common.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.media.themovieworld.R;
import com.media.themovieworld.api.ApiParams;
import com.media.themovieworld.model.CategoryModel;
import com.media.themovieworld.util.MovieImageLoader;
import com.media.themovieworld.widget.ViewHolder;

public class CategoryAdapter extends BaseListAdapter<CategoryModel>{

	private int imageSize;
	private int roundIcon;
	
	public CategoryAdapter(Activity activity, ArrayList<CategoryModel> datas) {
		super(activity, datas);
		if (mActivity!=null) {
			imageSize = mActivity.getResources().getDimensionPixelSize(R.dimen.category_image_size);
			roundIcon = mActivity.getResources().getDimensionPixelSize(R.dimen.category_image_round);
		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		if (row == null) {
			row = LayoutInflater.from(mActivity).inflate(R.layout.cate_data_items, null);
		}
		
		TextView tName = ViewHolder.get(row, R.id.tName);
		ImageView imgIcon = ViewHolder.get(row, R.id.row_icon);
		CategoryModel model = getItem(position);
		
		tName.setText(model.name);
		String url = ApiParams.getDownloadImageLink(imageSize, imageSize, model.icon);
		MovieImageLoader.getInstance().displayImage(url, imgIcon, MovieImageLoader.getDisplayImageOptionsRoundIcon(roundIcon));
		return row;
	}

}
